package com.ymatou.iapi.trading.userquery.testcase;

import java.math.BigDecimal;
import java.util.List;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.userquery.parameter.GetUserAccountInfoBean;
import com.ymatou.iapi.trading.userquery.service.GetUserAccountInfoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.database.model.Account;
import com.ymttest.database.sqlwapper.AccountWapper;
import com.ymttest.utils.EnvSetup;

/**
 * 获取用户帐户余额信息接口 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_GetUserAccountInfo {
	private static GetUserAccountInfoBean getuseraccountinfoBean;
	private static GetUserAccountInfoCall getuseraccountinfoCall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取用户帐户余额信息接口");
	}

	@Before
	public void caseUp() {
		getuseraccountinfoBean = new GetUserAccountInfoBean();
		getuseraccountinfoCall = new GetUserAccountInfoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getuseraccountinfoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GetUserAccountInfo_001() {
		Logger.start(true, "获取用户帐户余额信息成功");
		try {
			int userId = Integer.valueOf(EnvSetup.getData("BuyUserId"));
			getuseraccountinfoBean.setBuyerId(userId);

			getuseraccountinfoCall.setData(getuseraccountinfoBean);
			getuseraccountinfoCall.callService();

			List<Account> aids = new AccountWapper().selectAccountInfoByUserId(
					userId, 1);

			Logger.verifyEquals("200", getuseraccountinfoCall.getCode(),
					"验证code");

			Logger.verifyEquals(
					aids.get(0).getAvailAmount().stripTrailingZeros()
							.toPlainString(),
					new BigDecimal(getuseraccountinfoCall.getData().optString(
							"accountAmount")).stripTrailingZeros()
							.toPlainString(), "验证接口返回accountAmount");

			Logger.verifyEquals(true, getuseraccountinfoCall.getData()
					.getBoolean("existsTradingPwd"), "验证existsTradingPwd");

			Logger.verifyEquals(true, getuseraccountinfoCall.getData()
					.getBoolean("success"), "验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GetUserAccountInfo_002() {
		Logger.start(true, "用户id为null");
		try {

			getuseraccountinfoCall.setData(getuseraccountinfoBean);
			getuseraccountinfoCall.callService();

			Logger.verifyEquals("400", getuseraccountinfoCall.getCode(),
					"验证code");

			Logger.verifyEquals("100", getuseraccountinfoCall.getBCode(),
					"验证bcode");

			Logger.verifyEquals("buyerId:buyerId未提供",
					getuseraccountinfoCall.getMsg(), "验证msg");

			Logger.verifyEquals(true, getuseraccountinfoCall.getData()
					.getBoolean("existsTradingPwd"), "验证existsTradingPwd");

			Logger.verifyEquals(false, getuseraccountinfoCall.getData()
					.getBoolean("success"), "验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category({ P1.class })
	@TestCase
	public void Tc_GetUserAccountInfo_003() {
		Logger.start(true, "用户id不存在");
		try {

			getuseraccountinfoBean.setBuyerId(1223);

			getuseraccountinfoCall.setData(getuseraccountinfoBean);
			getuseraccountinfoCall.callService();

			Logger.verifyEquals("200", getuseraccountinfoCall.getCode(),
					"验证code");

			Logger.verifyEquals(
					BigDecimal.ZERO.setScale(1).stripTrailingZeros()
							.toPlainString(),
					new BigDecimal(getuseraccountinfoCall.getData().optString(
							"accountAmount")).stripTrailingZeros()
							.toPlainString(), "验证接口返回accountAmount");

			Logger.verifyEquals(true, getuseraccountinfoCall.getData()
					.getBoolean("existsTradingPwd"), "验证existsTradingPwd");

			Logger.verifyEquals(true, getuseraccountinfoCall.getData()
					.getBoolean("success"), "验证success");

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}